/**
 * Created by dev on 6/10/14.
 */

$(document).ready(function(){
    $Keyword_parent_ID = $( "input[name='keyID']").val();
    var base_url = $('body').data('baseurl');

    $('.parent').livequery('change', function() {
        $id = $(this).val();
        var url = base_url+'/autocomplete/child_category/'+$id;

        
        $(this).nextAll().remove();

        //$('#show_sub_categories').append('<img src="loader.gif" style="float:left; margin-top:7px;" id="loader" alt="" />');

        $.get(url, function(data, textStatus)
        {
            setTimeout(finishAjax('show_sub_categories', data), 400);
        });

        return false;
    });

    function finishAjax(id, response){
        $d = '#'+id;
        $('#loader').remove();
        $($d).append(response);
    }


    $('#selectbox-o').select2({
        //allowClear: true,
        //blurOnChange: true,
        //openOnEnter: false,
        //minimumInputLength: 1,
        ajax: {
            quietMillis: 100,
            url: base_url+"/autocomplete/category/term",
            dataType: 'json',
            data: function (term, page) {
                return {
                    q: term,
                    page_limit: 10
                };
            },

            results: function (data, page) {
                return { results: data };
            }
        }
    });

    $("#selectbox-o").on('change', function(e) {
        //I create a var data and works it like an Array
        var data = $(this).select2('data');
        //Then I take the values like if I work with an array
        var value = data.id;
        var text = data.text;
        //If I use console.log(var) the values are displayed but not with an alert
    });
//---------------------CATEGORY END-------------------------//

    $('#selectbox-location').select2({
        //placeholder: "Select Location",
        openOnEnter:true,
        allowClear: true,
        ajax: {
            quietMillis: 100,
            url: base_url+"/autocomplete/location/term",
            dataType: 'json',
            data: function (term, page) {

                return {
                    q: term,
                    page_limit: 10
                };
            },

            results: function (data, page) {
                return { results: data };
            }
        }
    });

    $("#selectbox-location").on('change', function(e) {
        //I create a var data and works it like an Array
        var data = $(this).select2('data');
        //Then I take the values like if I work with an array
        var value = data.id;
        var text = data.text;


        //If I use console.log(var) the values are displayed but not with an alert
    });
//---------------------LOCATION END-------------------------//

    $('#selectbox-location2').select2({

        //allowClear: true,
        blurOnChange: true,
        openOnEnter: false,
        //minimumInputLength: 1,
        ajax: {
            quietMillis: 100,
            url: base_url+"/autocomplete/location/term",
            dataType: 'json',
            data: function (term, page) {
                return {
                    q: term,
                    page_limit: 10
                };
            },

            results: function (data, page) {
                return { results: data };
            }
        }
    });

    $("#selectbox-location2").on('change', function(e) {
        //I create a var data and works it like an Array
        var data = $(this).select2('data');
        //Then I take the values like if I work with an array
        var value = data.id;
        var text = data.text;
        //If I use console.log(var) the values are displayed but not with an alert
    });
//---------------------LOCATION2 END-------------------------//


//---------------------MY LOCATION-------------------------//

    $('#selectbox-mylocation').select2({
        allowClear: true,
        blurOnChange: true,
        openOnEnter: false,
        minimumInputLength: 1,
        ajax: {
            quietMillis: 100,
            url: base_url+"/autocomplete/location/term",
            dataType: 'json',
            data: function (term, page) {
                return {
                    q: term,
                    page_limit: 10
                };
            },

            results: function (data, page) {
                return { results: data };
            }
        }
    });


    $("#selectbox-mylocation").on('change', function(e) {
        //I create a var data and works it like an Array
        var data = $(this).select2('data');
        //Then I take the values like if I work with an array
        var value = data.id;
        var text = data.text;
        //If I use console.log(var) the values are displayed but not with an alert
    });
//---------------------MY LOCATION END-------------------------//


    //---------------------MY LOCATION 1-------------------------//

    $('#selectbox-mylocation1').select2({
      //  allowClear: true,
        blurOnChange: true,
        openOnEnter: false,
        minimumInputLength: 1,
        ajax: {
            quietMillis: 100,
            url: base_url+"/autocomplete/location/term",
            dataType: 'json',
            data: function (term, page) {
                return {
                    q: term,
                    page_limit: 10
                };
            },

            results: function (data, page) {
                return { results: data };
            }
        }
    });


    $("#selectbox-mylocation1").on('change', function(e) {
        //I create a var data and works it like an Array
        var data = $(this).select2('data');
        //Then I take the values like if I work with an array
        var value = data.id;
        var text = data.text;
        //If I use console.log(var) the values are displayed but not with an alert
    });
//---------------------MY LOCATION1 END-------------------------//

    //---------------------MY LOCATION 2-------------------------//

    $('#selectbox-mylocation2').select2({
      //  allowClear: true,
        blurOnChange: true,
        openOnEnter: false,
        minimumInputLength: 1,
        ajax: {
            quietMillis: 100,
            url: base_url+"/autocomplete/location/term",
            dataType: 'json',
            data: function (term, page) {
                return {
                    q: term,
                    page_limit: 10
                };
            },

            results: function (data, page) {
                return { results: data };
            }
        }
    });


    $("#selectbox-mylocation2").on('change', function(e) {
        //I create a var data and works it like an Array
        var data = $(this).select2('data');
        //Then I take the values like if I work with an array
        var value = data.id;
        var text = data.text;
        //If I use console.log(var) the values are displayed but not with an alert
    });
//---------------------MY LOCATION2 END-------------------------//

    //---------------------MY LOCATION 3-------------------------//

    $('#selectbox-mylocation3').select2({
      //  allowClear: true,
        blurOnChange: true,
        openOnEnter: false,
        minimumInputLength: 1,
        ajax: {
            quietMillis: 100,
            url: base_url+"/autocomplete/location/term",
            dataType: 'json',
            data: function (term, page) {
                return {
                    q: term,
                    page_limit: 10
                };
            },

            results: function (data, page) {
                return { results: data };
            }
        }
    });


    $("#selectbox-mylocation3").on('change', function(e) {
        //I create a var data and works it like an Array
        var data = $(this).select2('data');
        //Then I take the values like if I work with an array
        var value = data.id;
        var text = data.text;
        //If I use console.log(var) the values are displayed but not with an alert
    });
//---------------------MY LOCATION3 END-------------------------//

  //---------------------MY LOCATION 4-------------------------//

    $('#selectbox-mylocation4').select2({
      //  allowClear: true,
        blurOnChange: true,
        openOnEnter: false,
        minimumInputLength: 1,
        ajax: {
            quietMillis: 100,
            url: base_url+"/autocomplete/location/term",
            dataType: 'json',
            data: function (term, page) {
                return {
                    q: term,
                    page_limit: 10
                };
            },

            results: function (data, page) {
                return { results: data };
            }
        }
    });


    $("#selectbox-mylocation4").on('change', function(e) {
        //I create a var data and works it like an Array
        var data = $(this).select2('data');
        //Then I take the values like if I work with an array
        var value = data.id;
        var text = data.text;
        //If I use console.log(var) the values are displayed but not with an alert
    });
//---------------------MY LOCATION4 END-------------------------//
 
    
  //---------------------MY LOCATION 5-------------------------//

    $('#selectbox-mylocation5').select2({
      //  allowClear: true,
        blurOnChange: true,
        openOnEnter: false,
        minimumInputLength: 1,
        ajax: {
            quietMillis: 100,
            url: base_url+"/autocomplete/location/term",
            dataType: 'json',
            data: function (term, page) {
                return {
                    q: term,
                    page_limit: 10
                };
            },

            results: function (data, page) {
                return { results: data };
            }
        }
    });


    $("#selectbox-mylocation5").on('change', function(e) {
        //I create a var data and works it like an Array
        var data = $(this).select2('data');
        //Then I take the values like if I work with an array
        var value = data.id;
        var text = data.text;
        //If I use console.log(var) the values are displayed but not with an alert
    });
//---------------------MY LOCATION5 END-------------------------//
    
  //---------------------MY LOCATION 6-------------------------//

    $('#selectbox-mylocation6').select2({
    	//placeholder: "Select Location",
        openOnEnter:true,
        allowClear: true,
        ajax: {
            quietMillis: 100,
            url: base_url+"/autocomplete/location/term",
            dataType: 'json',
            data: function (term, page) {

                return {
                    q: term,
                    page_limit: 10
                };
            },

            results: function (data, page) {
                return { results: data };
            }
        }
    });


    $("#selectbox-mylocation6").on('change', function(e) {
        //I create a var data and works it like an Array
        var data = $(this).select2('data');
        //Then I take the values like if I work with an array
        var value = data.id;
        var text = data.text;
        //If I use console.log(var) the values are displayed but not with an alert
    });
//---------------------MY LOCATION6 END-------------------------//
    
    
  //---------------------MY LOCATION 6-------------------------//

    $('#selectbox-mylocation7').select2({
    	//placeholder: "Select Location",
        openOnEnter:true,
        allowClear: true,
        ajax: {
            quietMillis: 100,
            url: base_url+"/autocomplete/location/term",
            dataType: 'json',
            data: function (term, page) {

                return {
                    q: term,
                    page_limit: 10
                };
            },

            results: function (data, page) {
                return { results: data };
            }
        }
    });


    $("#selectbox-mylocation7").on('change', function(e) {
        //I create a var data and works it like an Array
        var data = $(this).select2('data');
        //Then I take the values like if I work with an array
        var value = data.id;
        var text = data.text;
        //If I use console.log(var) the values are displayed but not with an alert
    });
//---------------------MY LOCATION6 END-------------------------//

    
    $('#selectbox-business').select2({

        //allowClear: true,
        blurOnChange: true,
        openOnEnter: false,
        minimumInputLength: 1,
        ajax: {
            quietMillis: 100,
            url: base_url+"/autocomplete/business/term",
            dataType: 'json',
            data: function (term, page) {
                return {
                    q: term,
                    page_limit: 10
                };
            },

            results: function (data, page) {
                return { results: data };
            }
        }
    });

    $("#selectbox-business").on('change', function(e) {
        //I create a var data and works it like an Array
        var data = $(this).select2('data');
        //Then I take the values like if I work with an array
        var value = data.id;
        var text = data.text;
        //If I use console.log(var) the values are displayed but not with an alert
    });
//---------------------BUSINESS END-------------------------//

    
    
    
    $('#selectbox-products').select2({

        //allowClear: true,
        blurOnChange: true,
        openOnEnter: false,
        //minimumInputLength: 1,
        ajax: {
            quietMillis: 100,
            url: base_url+"/autocomplete/products/term",
            dataType: 'json',
            data: function (term, page) {
                return {
                    q: term,
                    page_limit: 10
                };
            },

            results: function (data, page) {
                return { results: data };
            }
        }
    });

    $("#selectbox-products").on('change', function(e) {
        //I create a var data and works it like an Array
        var data = $(this).select2('data');
        //Then I take the values like if I work with an array
        var value = data.id;
        var text = data.text;
        //If I use console.log(var) the values are displayed but not with an alert
    });
//---------------------LOCATION2 END-------------------------//


    
    $('#selectbox-1').select2({
        //allowClear: true,
        //blurOnChange: true,
        //openOnEnter: false,
        //minimumInputLength: 1,
        ajax: {
            quietMillis: 100,
            url: base_url+"/autocomplete/category/term",
            dataType: 'json',
            data: function (term, page) {
                return {
                    q: term,
                    page_limit: 10
                };
            },

            results: function (data, page) {
                return { results: data };
            }
        }
    });

    $("#selectbox-1").on('change', function(e) {
        //I create a var data and works it like an Array
        var data = $(this).select2('data');
        //Then I take the values like if I work with an array
        var value = data.id;
        var text = data.text;
        //If I use console.log(var) the values are displayed but not with an alert
    });
//---------------------CATEGORY END-------------------------//

    $('#selectbox-2').select2({
        //allowClear: true,
        //blurOnChange: true,
        //openOnEnter: false,
        //minimumInputLength: 1,
        ajax: {
            quietMillis: 100,
            url: base_url+"/autocomplete/category/term",
            dataType: 'json',
            data: function (term, page) {
                return {
                    q: term,
                    page_limit: 10
                };
            },

            results: function (data, page) {
                return { results: data };
            }
        }
    });

    $("#selectbox-2").on('change', function(e) {
        //I create a var data and works it like an Array
        var data = $(this).select2('data');
        //Then I take the values like if I work with an array
        var value = data.id;
        var text = data.text;
        //If I use console.log(var) the values are displayed but not with an alert
    });
//---------------------CATEGORY END-------------------------//
    
    $('#selectbox-3').select2({
        //allowClear: true,
        //blurOnChange: true,
        //openOnEnter: false,
        //minimumInputLength: 1,
        ajax: {
            quietMillis: 100,
            url: base_url+"/autocomplete/category/term",
            dataType: 'json',
            data: function (term, page) {
                return {
                    q: term,
                    page_limit: 10
                };
            },

            results: function (data, page) {
                return { results: data };
            }
        }
    });

    $("#selectbox-3").on('change', function(e) {
        //I create a var data and works it like an Array
        var data = $(this).select2('data');
        //Then I take the values like if I work with an array
        var value = data.id;
        var text = data.text;
        //If I use console.log(var) the values are displayed but not with an alert
    });
    
    $('#selectbox-4').select2({
        //allowClear: true,
        //blurOnChange: true,
        //openOnEnter: false,
        //minimumInputLength: 1,
        ajax: {
            quietMillis: 100,
            url: base_url+"/autocomplete/category/term",
            dataType: 'json',
            data: function (term, page) {
                return {
                    q: term,
                    page_limit: 10
                };
            },

            results: function (data, page) {
                return { results: data };
            }
        }
    });

    $("#selectbox-4").on('change', function(e) {
        //I create a var data and works it like an Array
        var data = $(this).select2('data');
        //Then I take the values like if I work with an array
        var value = data.id;
        var text = data.text;
        //If I use console.log(var) the values are displayed but not with an alert
    });
    
    
    $('#selectbox-5').select2({
        //allowClear: true,
        //blurOnChange: true,
        //openOnEnter: false,
        //minimumInputLength: 1,
        ajax: {
            quietMillis: 100,
            url: base_url+"/autocomplete/category/term",
            dataType: 'json',
            data: function (term, page) {
                return {
                    q: term,
                    page_limit: 10
                };
            },

            results: function (data, page) {
                return { results: data };
            }
        }
    });

    $("#selectbox-5").on('change', function(e) {
        //I create a var data and works it like an Array
        var data = $(this).select2('data');
        //Then I take the values like if I work with an array
        var value = data.id;
        var text = data.text;
        //If I use console.log(var) the values are displayed but not with an alert
    });
    
    
    
});

